package modelTest;

import static org.junit.Assert.*;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.GregorianCalendar;

import model.Auction;
import model.Item;
import model.NPO;

import org.junit.Before;
import org.junit.Test;

/**
 * Tests the Auction class
 * 
 * @author Daniel Bartholomew
 */
public class AuctionTest {
	
	/** A date format used to create dates from Strings in testing */
	private static DateFormat my_format = DateFormat.getDateInstance(DateFormat.MEDIUM);
		
	private static NPO testNPO;
	
	private Auction testAuction;
	
	@Before
	public void initialize() {
		testNPO = new NPO("NPOname");
		Calendar date = new GregorianCalendar();
		try {
			date.setTime(my_format.parse("June 11, 2012"));
		} catch (ParseException e) {
			fail("Bad Date");
		}
		testAuction = new Auction(testNPO, date, 2.5);
	}
	
	@Test
	public void testAuctionCreation() {
		assertEquals("NPO Test", testNPO, testAuction.getNPO());
		assertEquals("Name Test", "NPOname Jun 11, 2012", testAuction.getName());
		assertEquals("Duration Test", 2.5, testAuction.getDuration(), .0005);
	}
	
	@Test
	public void testAddItem() {
		Item testItem1 = new Item("TestItem1", 20, "Meh");
		Item testItem2 = new Item("TestItem2", 5.99, "ZZZZ");
		
		assertTrue("Add First Item", testAuction.addItem(testItem1));
		assertTrue("Add Second Item", testAuction.addItem(testItem2));
		assertFalse("Add Duplicate", testAuction.addItem(testItem1));
	}

}
